//#define AttributesTest
//#define PerksTest
//#define InventoryTest

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class TestPlayer : MonoBehaviour {
	
	public float playerIndex;
	public bool isActive;
	private bool guiOn;
	/// <summary>
	/// El AttributeSet se crea en el personaje y desde ahi se maneja todo lo que
	/// tiene que ver con atributos y subatributos, es un contenedor-manager.
	/// </summary>
	AttributeSet attributeSet;
	
	Perks.PerkSet perkSet;
	
	Inventory inventory;
	void Start () {
		guiOn = false;
	/*	attributeSet = new AttributeSet();
		perkSet = new Perks.PerkSet(attributeSet);
		inventory = new Inventory();
		InventoryController.GetInstance().SetActiveInventory(this.inventory);
		AttributesController.GetInstance().SetActiveCharacter(this.attributeSet);
	*/
		AttributesController.GetInstance().SetActiveCharacter(
			CharacterDataManager.GetInstance().GetCurrentCharData().attributes );
	}
	void Update(){
		if (!isActive)
			return;
				
#if AttributesTest
		if (Input.GetKeyDown(KeyCode.A) ){
			attributeSet.RaiseAttributeBaseValue(ATTRIBUTES.AGILITY, 1);
		}
		if (Input.GetKeyDown(KeyCode.C) ){
			attributeSet.RaiseAttributeBaseValue(ATTRIBUTES.CONSTITUTION, 1);
		}
		if (Input.GetKeyDown(KeyCode.X) ){
			attributeSet.AddPercetageBonusToAttribute(ATTRIBUTES.CONSTITUTION, 1);
		}
		if (Input.GetKeyDown(KeyCode.D) ){
			attributeSet.RaiseAttributeBaseValue(ATTRIBUTES.DEXTERITY, 1);
		}
		if (Input.GetKeyDown(KeyCode.T) ){
			attributeSet.RaiseAttributeBaseValue(ATTRIBUTES.TECHNIQUE, 1);
		}
		if (Input.GetKeyDown(KeyCode.S) ){
			attributeSet.RaiseAttributeBaseValue(ATTRIBUTES.STRENGTH, 1);
		}
		if (Input.GetKeyDown(KeyCode.Space) ){
			attributeSet.AddBonusToAttribute(ATTRIBUTES.AGILITY,1);
			attributeSet.AddBonusToAttribute(ATTRIBUTES.DEXTERITY,1);
			attributeSet.AddBonusToAttribute(ATTRIBUTES.CONSTITUTION,1);
			attributeSet.AddBonusToAttribute(ATTRIBUTES.TECHNIQUE,1);
			attributeSet.AddBonusToAttribute(ATTRIBUTES.STRENGTH,1);
		}
		
		if (Input.GetKeyDown(KeyCode.H) ){
			attributeSet.AddBonusToSubAttribute(SUB_ATTRIBUTES.HIT_POINTS, 1);
		}
		if (Input.GetKeyDown(KeyCode.J) ){
			attributeSet.ModifySubAttributeActualValue(SUB_ATTRIBUTES.STAMINA, -10);
		}
#endif		
#if PerksTest
		if (Input.GetKeyDown(KeyCode.P) ){
			perkSet.Equip(Perks.FastManeuvers.Name);
			perkSet.Equip(Perks.DoubleStamina.Name);
		}
		if (Input.GetKeyDown(KeyCode.O) ){
			perkSet.UnEquip(Perks.FastManeuvers.Name);
			perkSet.UnEquip(Perks.DoubleStamina.Name);
		}
#endif
#if InventoryTest
		if (Input.GetKeyDown(KeyCode.I) ){
			InventoryController.GetInstance().ShowGUI(true);
	//		Debug.LogWarning( inventory.StockItem(new TestItem() )) ;
		}
		if (Input.GetKeyDown(KeyCode.K) ){
			InventoryController.GetInstance().ShowGUI(false);
		}
		if (Input.GetKeyDown(KeyCode.J) ){
			InventoryController.GetInstance().DrawSlots();
		}
#endif

		if (Input.GetKeyDown(KeyCode.Q) ){
			guiOn = !guiOn;
			PopUpManager.instance.ShowMenu(guiOn, PopUpManager.POPUP_MENUS.GAMEOVER);
			//AttributesController.GetInstance().ShowGUI(guiOn);
		}
		if (Input.GetKeyDown(KeyCode.W) ){
			guiOn = !guiOn;
			PopUpManager.instance.ShowMenu(guiOn, PopUpManager.POPUP_MENUS.PAUSE);
			//AttributesController.GetInstance().ShowGUI(guiOn, true);
		}
		if (Input.GetKeyDown(KeyCode.Minus) ){
			CharacterDataManager.GetInstance().GetCurrentCharData().attributes
			.ModifySubAttributeActualValue(SUB_ATTRIBUTES.HIT_POINTS, -1);
			CharacterDataManager.GetInstance().GetCurrentCharData().attributes
			.ModifySubAttributeActualValue(SUB_ATTRIBUTES.STAMINA, -1);
		}
		if (Input.GetKeyDown(KeyCode.KeypadPlus) ){
			CharacterDataManager.GetInstance().GetCurrentCharData().attributes
			.ModifySubAttributeActualValue(SUB_ATTRIBUTES.HIT_POINTS, 1);
			CharacterDataManager.GetInstance().GetCurrentCharData().attributes
			.ModifySubAttributeActualValue(SUB_ATTRIBUTES.STAMINA, 1);
		}
        if (Input.GetKeyDown(KeyCode.K))
        {
            Application.LoadLevel("Ivan");
        }
	}

/*	void OnGUI(){
		//Attributes
		GUI.Box( new Rect(10+300*playerIndex,10,300,100), 
			"STRENGTH: " + attributeSet.GetAttributeBaseValue(ATTRIBUTES.STRENGTH) + " + " + attributeSet.GetAttributeBonusValue(ATTRIBUTES.STRENGTH) + " + %(" + attributeSet.GetAttributePercentageBonus(ATTRIBUTES.STRENGTH) + ")= " + attributeSet.GetAttributeTotalValue(ATTRIBUTES.STRENGTH) + "\n" +
			"DEXTERITY: " + attributeSet.GetAttributeBaseValue(ATTRIBUTES.DEXTERITY) + " + " + attributeSet.GetAttributeBonusValue(ATTRIBUTES.DEXTERITY) + " + %(" + attributeSet.GetAttributePercentageBonus(ATTRIBUTES.DEXTERITY) +  ")= " + attributeSet.GetAttributeTotalValue(ATTRIBUTES.DEXTERITY) + "\n" +
			"CONSTITUTION: " + attributeSet.GetAttributeBaseValue(ATTRIBUTES.CONSTITUTION) + " + " + attributeSet.GetAttributeBonusValue(ATTRIBUTES.CONSTITUTION) + " + %(" + attributeSet.GetAttributePercentageBonus(ATTRIBUTES.CONSTITUTION) +  ")= " + attributeSet.GetAttributeTotalValue(ATTRIBUTES.CONSTITUTION) + "\n" +
			"AGILITY: " + attributeSet.GetAttributeBaseValue(ATTRIBUTES.AGILITY) + " + " + attributeSet.GetAttributeBonusValue(ATTRIBUTES.AGILITY) + " + %(" + attributeSet.GetAttributePercentageBonus(ATTRIBUTES.AGILITY) +  ")= " + attributeSet.GetAttributeTotalValue(ATTRIBUTES.AGILITY) + "\n" +
			"TECHNIQUE: " + attributeSet.GetAttributeBaseValue(ATTRIBUTES.TECHNIQUE) + " + " + attributeSet.GetAttributeBonusValue(ATTRIBUTES.TECHNIQUE) + " + %(" + attributeSet.GetAttributePercentageBonus(ATTRIBUTES.TECHNIQUE) +  ")= " + attributeSet.GetAttributeTotalValue(ATTRIBUTES.TECHNIQUE));
		//Sub-Attributes
		GUI.Box( new Rect(10+300*playerIndex,110,300,100), 
			"HP: " + attributeSet.GetSubAttributeBaseValue(SUB_ATTRIBUTES.HIT_POINTS) + "+ " + attributeSet.GetSubAttributeBonusValue(SUB_ATTRIBUTES.HIT_POINTS) + " +("+attributeSet.GetDependenciesBonusOfSubAttribute(SUB_ATTRIBUTES.HIT_POINTS)+") " + "+ %(" + attributeSet.GetSubAttributePercentageBonus(SUB_ATTRIBUTES.HIT_POINTS) + ")= " + attributeSet.GetSubAttributeActualValue(SUB_ATTRIBUTES.HIT_POINTS) + "/" + attributeSet.GetSubAttributeMaxValue(SUB_ATTRIBUTES.HIT_POINTS) + "\n" +
			"Speed: " + attributeSet.GetSubAttributeBaseValue(SUB_ATTRIBUTES.MOVEMENT_SPEED) + "+ " + attributeSet.GetSubAttributeBonusValue(SUB_ATTRIBUTES.MOVEMENT_SPEED) + " +("+attributeSet.GetDependenciesBonusOfSubAttribute(SUB_ATTRIBUTES.MOVEMENT_SPEED)+") " + "+ %(" + attributeSet.GetSubAttributePercentageBonus(SUB_ATTRIBUTES.MOVEMENT_SPEED) + ")= " + attributeSet.GetSubAttributeActualValue(SUB_ATTRIBUTES.MOVEMENT_SPEED) + "/" + attributeSet.GetSubAttributeMaxValue(SUB_ATTRIBUTES.MOVEMENT_SPEED) + "\n" +
			"Inventory Slots: " + attributeSet.GetSubAttributeBaseValue(SUB_ATTRIBUTES.INVENTORY_SLOTS) + " + " + attributeSet.GetSubAttributeBonusValue(SUB_ATTRIBUTES.INVENTORY_SLOTS) + " + %(" + attributeSet.GetSubAttributePercentageBonus(SUB_ATTRIBUTES.INVENTORY_SLOTS) + ")= " + attributeSet.GetSubAttributeActualValue(SUB_ATTRIBUTES.INVENTORY_SLOTS) + "/" + attributeSet.GetSubAttributeMaxValue(SUB_ATTRIBUTES.INVENTORY_SLOTS) + "\n" +
			"Reload Time: "+ attributeSet.GetSubAttributeBaseValue(SUB_ATTRIBUTES.RELOAD_TIME) + " + " + attributeSet.GetSubAttributeBonusValue(SUB_ATTRIBUTES.RELOAD_TIME) + " +("+attributeSet.GetDependenciesBonusOfSubAttribute(SUB_ATTRIBUTES.RELOAD_TIME)+") " + " + %(" + attributeSet.GetSubAttributePercentageBonus(SUB_ATTRIBUTES.RELOAD_TIME) + ")= " + attributeSet.GetSubAttributeActualValue(SUB_ATTRIBUTES.RELOAD_TIME) + "/" + attributeSet.GetSubAttributeMaxValue(SUB_ATTRIBUTES.RELOAD_TIME) + "\n" +
			"Noise Factor: " + attributeSet.GetSubAttributeBaseValue(SUB_ATTRIBUTES.NOISE_FACTOR) + " + " + attributeSet.GetSubAttributeBonusValue(SUB_ATTRIBUTES.NOISE_FACTOR) + " +("+attributeSet.GetDependenciesBonusOfSubAttribute(SUB_ATTRIBUTES.NOISE_FACTOR)+") " + "+ %(" + attributeSet.GetSubAttributePercentageBonus(SUB_ATTRIBUTES.NOISE_FACTOR) + ")= " + attributeSet.GetSubAttributeActualValue(SUB_ATTRIBUTES.NOISE_FACTOR) + "/" + attributeSet.GetSubAttributeMaxValue(SUB_ATTRIBUTES.NOISE_FACTOR) + "\n" +
			"Stamina: " + attributeSet.GetSubAttributeBaseValue(SUB_ATTRIBUTES.STAMINA) + " + " + attributeSet.GetSubAttributeBonusValue(SUB_ATTRIBUTES.STAMINA) + " +("+attributeSet.GetDependenciesBonusOfSubAttribute(SUB_ATTRIBUTES.STAMINA)+") " + "+ %(" + attributeSet.GetSubAttributePercentageBonus(SUB_ATTRIBUTES.STAMINA) + ")= " + attributeSet.GetSubAttributeActualValue(SUB_ATTRIBUTES.STAMINA) + "/" + attributeSet.GetSubAttributeMaxValue(SUB_ATTRIBUTES.STAMINA) );
		//Perks
		GUI.Box(new Rect(10+300*playerIndex,220,300,30), "Perk Points: " + perkSet.GetAvailablePoints() +"/"+ perkSet.GetCapacityPoints() );
				
		for(int i=0; i<perkSet.GetEquippedPerks().Count; i++){
			GUI.Box(new Rect(310,40+(30*i),300,30), "Equipped Perk[" +i+ "] " + perkSet.GetEquippedPerks()[i] );
		}
	}*/
}
